﻿@{
    ViewBag.Title = "Register";
    Layout = "";
}

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>注册页面</title>
    <meta name="viewport" content="user-scalable=no,initial-scale=1,maximum-scale=1,minimum-scale=1">
    <script src="~/Scripts/jquery-1.9.1.min.js"></script>
    <link href="~/Content/reset.css" rel="stylesheet" type="text/css" />
    <link href="~/Content/loginAndRegisterCommon.css" rel="stylesheet" type="text/css" />
    <link href="~/Content/form.css" rel="stylesheet" type="text/css" />
    <link href="~/Content/register.css" rel="stylesheet" type="text/css" />
    <link href="~/Content/alertStyle.css" rel="stylesheet" type="text/css" />
    <script src="~/Scripts/alert.js" type="text/javascript"></script>

    <script>
    var _hmt = _hmt || [];
    (function () {
        var hm = document.createElement("script");
        hm.src = "https://hm.baidu.com/hm.js?4fd648fda0a3af92d7a11dfd25b34442";
        var s = document.getElementsByTagName("script")[0];
        s.parentNode.insertBefore(hm, s);
    })();
    </script>
</head>
<body>
    <div class="header">
        <div class="h_back">
            <a href="javascript:history.back(-1)">
                <img src="~/Content/img/iconfont-fanhui.png" />
            </a>
        </div>
        <h1 class="h_title">
            注册
        </h1>
        <div class="h_btn">
            <a href="/Home/Login">登录</a>
        </div>
    </div>
    <div class="main" style="margin-top: 20px">
        <div class="input-form">
            <ul>
                <li>
                    <span>手机号： </span>
                    <div class="input-form-box">
                        <input class="iphone-number" type="text" name="phone" id="phone" value="" placeholder="请输入手机号" />
                    </div>
                </li>
                <li>
                    <span>验证码： </span>
                    <div class="input-form-box">
                        <input type="text" name="code" id="code" value="" placeholder="请输入验证码" class="min-box" maxlength="6" />
                    </div>
                    <a style="height:2rem" class="send-message" id="getCode" flag="true">获取验证码</a>
                </li>
                <li>
                    <span>密码：</span>
                    <div class="input-form-box">
                        <input class="iphone-number" type="password" name="password" id="password" value="" placeholder="请输入密码" />
                    </div>
                </li>
                <li>
                    <span>确认密码：</span>
                    <div class="input-form-box">
                        <input class="iphone-number" type="password" name="confirmPassword" id="confirmPassword" value="" placeholder="两次密码必须一致" />
                    </div>
                </li>
            </ul>
        </div>
        <a href="javascript:;" class="jd_btn">注册</a>
    </div>
    <div class="copy">
        <p>Copyright@2015-2016, AII Rights Reserved </p>
        <p>广西爱农人电子商务有限公司</p>
        <p>桂ICP备16003246号-1</p>
    </div>

</body>
</html>

<script>
    $(function () {
        $(".send-message").on("click", function () {
            var phone = $.trim($("#phone").val());
            var reg = /^(1[3|4|5|7|8][0-9]{9}$)|(178[0-9]{8}$)/g;
            var flag = reg.test(phone);
            if (!flag) {
                $.fn.SK_alert("请输入格式正确的手机号码！");
                return;
            }
            if ($(this).attr("flag") == "true") {
                $(this).attr("flag", "false");
                sendMessage();
            }
        });


        var time;
        function sendMessage() {
            var phone = $.trim($("#phone").val());
            $.ajax({
                type: "post",
                url: "@Url.Action("SendRegisterMessage")",
                data: { phone: phone },
                success: function (data) {
                    if (data.flag) {
                        $.fn.SK_alert(data.content);
                        time = 120; //设置获取验证码的时间间隔为120秒
                        $("#phone").attr("disabled", "disabled");//电话禁止修改
                        showTime();
                    } else {
                        $(".send-message").attr("flag", "true");
                        $.fn.SK_alert(data.content);
                    }
                }
            });
        }


        function showTime() {
            $("#getCode").text(time + "s");
            time--;
            if (time > 0) {
                setTimeout(showTime, 1000);
            } else {
                $("#getCode").text("获取验证码");
                $(".send-message").attr("flag", "true");
            }
        }

        $(".jd_btn").on("click", function () {
            var phone = $.trim($("#phone").val());
            var code = $.trim($("#code").val());
            var password = $.trim($("#password").val());
            var confirmPassword = $.trim($("#confirmPassword").val());

            if (code == "") {
                $.fn.SK_alert("请输入验证码！");
                return;
            }
            if (password == "") {
                $.fn.SK_alert("请输入密码！");
                return;
            }

            var reg = /^[A-Za-z][A-Za-z0-9]{5,21}$/g; //以字母开头，数字和字母结尾
            var reg2 = /^[A-Za-z]+$/g                 //不能全是字母
            var r = reg.test(password);
            var r2 = reg2.test(password);
            if (r) {
                if (r2) {
                    $.fn.SK_alert("密码以字母开头,由数字、字母混合组成！");
                    return;
                }
            } else {
                $.fn.SK_alert("密码以字母开头,由数字、字母混合组成！");
                return;
            }
            if (password != confirmPassword) {
                $.fn.SK_alert("两次输入的密码不相同！");
                return;
            }
            $.ajax({
                type: "post",
                url: "@Url.Action("SumitPhoneCode")",
                data: { phone: phone, code: code },
                success: function (data) {
                    if (data.flag) {
                        regist();
                    } else {
                        $.fn.SK_alert(data.content);
                        return;
                    }
                }
            });
        });
    })

    function regist() {
        var phone = $.trim($("#phone").val());
        var password = $.trim($("#password").val());
        $.ajax({
            type: "post",
            url: '@Url.Action("RegisterAction")',
            data: { phone: phone, password: password },
            async: false,
            success: function (result) {
                if (result.flag) {
                    window.location.href = "/Home/Votes";
                } else {
                    $.fn.SK_alert(result.content);
                }
            }
        });
    }
</script>



@*<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>注册页面</title>
    <meta name="viewport" content="user-scalable=no,initial-scale=1,maximum-scale=1,minimum-scale=1">
    <script src="~/Scripts/jquery-1.9.1.min.js"></script>
    <link href="~/Content/reset.css" rel="stylesheet" type="text/css" />
    <link href="~/Content/loginAndRegisterCommon.css" rel="stylesheet" type="text/css" />
    <link href="~/Content/form.css" rel="stylesheet" type="text/css" />
    <link href="~/Content/register.css" rel="stylesheet" type="text/css" />
    <link href="~/Content/alertStyle.css" rel="stylesheet" type="text/css" />
    <script src="~/Scripts/alert.js" type="text/javascript"></script>
</head>
<body>
    <div class="header">
        <div class="h_back">
            <a href="javascript:history.back(-1)">
                <img src="~/Content/img/iconfont-fanhui.png" />
            </a>
        </div>
        <h1 class="h_title">
            注册
        </h1>
        <div class="h_btn">
            <a href="/Home/Login">登录</a>
        </div>
    </div>
    <div class="main" style="margin-top: 20px">
        <div class="input-form">
            <ul>
                <li>
                    <span>手机号： </span>
                    <div class="input-form-box">
                        <input class="iphone-number" type="text" name="phone" id="phone" value="" placeholder="请输入手机号" />
                    </div>
                </li>
                <li>
                    <span>密码：</span>
                    <div class="input-form-box">
                        <input class="iphone-number" type="password" name="password" id="password" value="" placeholder="请输入密码" />
                    </div>
                </li>
                <li>
                    <span>确认密码：</span>
                    <div class="input-form-box">
                        <input class="iphone-number" type="password" name="confirmPassword" id="confirmPassword" value="" placeholder="两次密码必须一致" />
                    </div>
                </li>
            </ul>
        </div>
        <a href="javascript:;" class="jd_btn">注册</a>
    </div>
    <div class="copy">
        <p>Copyright@2015-2016, AII Rights Reserved </p>
        <p>广西爱农人电子商务有限公司</p>
        <p>桂ICP备16003246号-1</p>
    </div>

</body>
</html>

<script>
    $(function () {
       
        $(".jd_btn").on("click", function () {
            var phone = $.trim($("#phone").val());
            var password = $.trim($("#password").val());
            var confirmPassword = $.trim($("#confirmPassword").val());

            var regPhone = /^(1[3|4|5|7|8][0-9]{9}$)|(178[0-9]{8}$)/g;
            var flag = regPhone.test(phone);
            if (!flag) {
                $.fn.SK_alert("请输入格式正确的手机号码！");
                return;
            }

            if (password == "") {
                $.fn.SK_alert("请输入密码！");
                return;
            }

            var reg = /^[A-Za-z][A-Za-z0-9]{5,21}$/g; //以字母开头，数字和字母结尾
            var reg2 = /^[A-Za-z]+$/g                 //不能全是字母
            var r = reg.test(password);
            var r2 = reg2.test(password);
            if (r) {
                if (r2) {
                    $.fn.SK_alert("密码以字母开头,由数字、字母混合组成！");
                    return;
                }
            } else {
                $.fn.SK_alert("密码以字母开头,由数字、字母混合组成！");
                return;
            }
            if (password != confirmPassword) {
                $.fn.SK_alert("两次输入的密码不相同！");
                return;
            }
            $.ajax({
                type: "post",
                url: '@Url.Action("RegisterAction")',
                data: { phone: phone, password: password },
                async: false,
                success: function (result) {
                    if (result.flag) {
                        window.location.href = "/Home/Votes";
                    } else {
                        $.fn.SK_alert(result.content);
                    }
                }
            });
        });
    })
</script>*@
